package cn.hairui.blog.mapper;

import cn.hairui.blog.model.Tool;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
import java.util.Map;

/**
 * @author lihairui
 * @version V1.0
 * @date: 2019/7/28 22:27
 */
@Mapper
public interface ToolMapper extends BaseMapper<Tool> {

    @Select("SELECT * FROM TOOL ORDER BY ID DESC  LIMIT 0,#{count}")
    List<Tool> findLimited(int count);

    @Select("SELECT * FROM TOOL WHERE ID=#{id}")
    Tool find(int id);

    @Select("SELECT ID AS id,TOOL_NAME AS toolName,URL AS url,INTRODUCE AS introduce,ADD_DATE AS addDate FROM TOOL ORDER BY ID ASC")
    List<Map> listMgr();

    @Update("UPDATE TOOL SET TOOL_NAME=@{toolName},URL=#{url},INTRODUCE=#{introduce} WHERE ID=#{id}")
    void update(Tool tool);

    @Delete("DELETE FROM TOOL WHERE ID=#{id}")
    void deleteById(int id);

    @Select("SELECT * FROM TOOL ORDER BY ID DESC")
    List<Tool> list();
}
